package com.carnation.service.impl;

import org.apache.log4j.Logger;
import org.quartz.CronScheduleBuilder;
import org.quartz.JobBuilder;
import org.quartz.JobDetail;
import org.quartz.Scheduler;
import org.quartz.SchedulerFactory;
import org.quartz.Trigger;
import org.quartz.TriggerBuilder;
import org.quartz.impl.StdSchedulerFactory;

import com.carnation.job.UploadJob;
import com.carnation.service.JobMgrServer;
import com.carnation.utils.MenuFileUtril;

public class JobMgrServerImpl implements JobMgrServer{

	private Logger logger = Logger.getLogger(JobMgrServerImpl.class);
	
	@Override
	public void start() {
		try{
			MenuFileUtril menuFileUtril = new MenuFileUtril();
			SchedulerFactory sf = new StdSchedulerFactory();
			Scheduler scheduler = sf.getScheduler();
			JobDetail jobDetail = JobBuilder.newJob(UploadJob.class).withIdentity("uploadJob", "ftpgroup").build();
			Trigger trigger = TriggerBuilder.newTrigger().withIdentity("uploadTrigger","ftpTriggerGroup").withSchedule(CronScheduleBuilder.cronSchedule(menuFileUtril.getUploadCronTime())).build();
			scheduler.scheduleJob(jobDetail, trigger);
			scheduler.start();
			System.out.println("任务已启动");
		}
		catch(Exception e){
			logger.error("获取schedule出错",e);
		}
	}
	
}
